/*
 * The function notifyme shows a notification to the user
 * when the record will be saved.
 */
function notifyme(action, formnm, presyr, pressubj) {

 /* If the user intends to save the records in an existing
  * file, display two alert boxes.
  */
 if(action == 'sovr') {
  if(decis = confirm("You will be overwriting the existing records. Are you sure?") == true) {
   if(decis2 = confirm("The previous records written before will be permanently deleted. Are you sure?") == true) {
    saveonedb(formnm, presyr, pressubj);
    return true; 
   }
   else {
    return false;
   }
  }
  else {
   return false;
  }
 }
 
 /*
  * If the user intends to save the records in a new file,
  * display a prompt box that will capture the name of the
  * file to be saved.
  */
 else if(action == 'snew') {
  if(decis = confirm("You will be saving the grades in a new file. Are you sure?") == true) {
   if(promptnm = prompt("Please enter the filename of the new record:")) {
    var appendme = document.createElement("input");
	appendme.setAttribute("type", "hidden");
	appendme.setAttribute("name", "flname");
	appendme.setAttribute("value", promptnm);
	document.forms[formnm].appendChild(appendme);
	saveonedb(formnm, presyr, pressubj);
    return true;
   }
   else {
    return false;
   }
  }
  else {
   return false
  }
 }
}

/*
 * The function saveonedb submits edited grades for
 * one subject.
 */
function saveonedb(formtosubmit, yr, subj) {
 var yrid = document.createElement("input");
 var subjid = document.createElement("input");
 
 yrid.setAttribute("type", "hidden");
 yrid.setAttribute("name", "yrplaced");
 yrid.setAttribute("value", yr);
 
 subjid.setAttribute("type", "hidden");
 subjid.setAttribute("name", "subjplaced");
 subjid.setAttribute("value", subj);

 document.forms[formtosubmit].appendChild(yrid);
 document.forms[formtosubmit].appendChild(subjid);
}

function getfile() {
 document.forms['filefrm'].submit();
}